package com.gary.C3P0;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class C3P0 {
	private static ComboPooledDataSource dataSource=null;
	public C3P0(){
		init();
	}
	public static void init(){
		dataSource=new ComboPooledDataSource();
		try{
			dataSource.setDriverClass("com.mysql.jdbc.Driver");
			dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/breaks?" +
					"useUnicode=true&amp;characterEncoding=GBK");
			dataSource.setUser("root");
			dataSource.setPassword("");
			dataSource.setMaxPoolSize(500);
			dataSource.setMinPoolSize(30);
			dataSource.setInitialPoolSize(30);
		}catch(Exception e){
			System.out.println(e.toString());
		}
	}
	public static synchronized Connection getConnection() 
	throws 	SQLException{
		return  dataSource.getConnection();
	}
	
	public static void main(String args[]){
		try {
			Connection conn=new C3P0().getConnection();
			Statement sta=conn.createStatement();
			ResultSet resultset=sta.executeQuery("select * from user");
			while(resultset.next()){
				System.out.println(resultset.getString("user_name"));
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
